import { createRouter, createWebHashHistory } from "vue-router";
import LocalCache from "@/utils/storage";
import type { RouteRecordRaw } from "vue-router";

const routes: Array<RouteRecordRaw> = [
  // {
  //   path: "/",
  //   redirect: "/home",
  // },
  {
    path: "/ces",
    name: "Ces",
    component: () => import("@/views/ces/one.vue"),
  },
  // {
  //   path: "/home",
  //   name: "Home",
  //   component: () => import("@/views/home/index.vue"),
  // },
  {
    path: "/menu",
    name: "Menu",
    component: () => import("@/views/menu/index.vue"),
  },

  // 人事模块
  {
    path: "/person",
    name: "Person",
    children: [
      // 人员
      {
        path: "employee",
        name: "PersonEmployee",
        component: () => import("@/views/person/employee/index.vue"),
      },
      {
        path: "addPosition",
        name: "AddPersonEmployee",
        component: () => import("@/views/person/employee/add.vue"),
      },
      {
        path: "editPosition",
        name: "EditPersonEmployee",
        component: () => import("@/views/person/employee/edit.vue"),
      },
      {
        path: "recoverEmployee",
        name: "RecoverEmployee",
        component: () => import("@/views/person/employee/recover.vue"),
      },

      // 职位
      {
        path: "position",
        name: "PersonPosition",
        component: () => import("@/views/person/position/index.vue"),
      },
      {
        path: "addPosition",
        name: "AddPersonPosition",
        component: () => import("@/views/person/position/add.vue"),
      },
      {
        path: "editPosition",
        name: "EditPersonPosition",
        component: () => import("@/views/person/position/edit.vue"),
      },
      // 组织
      {
        path: "organization",
        name: "PersonOrganization",
        component: () => import("@/views/person/organization/index.vue"),
      },
      {
        path: "addPosition",
        name: "AddPersonOrganization",
        component: () => import("@/views/person/organization/add.vue"),
      },
      {
        path: "editPosition",
        name: "EditPersonOrganization",
        component: () => import("@/views/person/organization/edit.vue"),
      },
    ],
  },

  // 门禁模块
  {
    path: "/access",
    name: "Access",
    children: [
      // 权限
      {
        path: "casbin",
        name: "AccessCasbin",
        component: () => import("@/views/access/casbin/index.vue"),
      },
      {
        path: "casbinAdd",
        name: "AccessCasbinAdd",
        component: () => import("@/views/access/casbin/addCasbin.vue"),
      },
      {
        path: "casbinEdit",
        name: "AccessCasbinEdit",
        component: () => import("@/views/access/casbin/editCasbin.vue"),
      },
      {
        path: "casbinDoor",
        name: "AccessCasbinDoor",
        component: () => import("@/views/access/casbin/doorList.vue"),
      },
      {
        path: "casbinDoorAdd",
        name: "AccessCasbinDoorAdd",
        component: () => import("@/views/access/casbin/addDoor.vue"),
      },
      {
        path: "casbinEmployee",
        name: "AccessCasbinEmployee",
        component: () => import("@/views/access/casbin/employeeList.vue"),
      },
      {
        path: "casbinEmployeeAdd",
        name: "AccessCasbinEmployeeAdd",
        component: () => import("@/views/access/casbin/addEmployee.vue"),
      },

      // 设备
      {
        path: "dev",
        name: "AccessDev",
        component: () => import("@/views/access/dev/index.vue"),
      },
      {
        path: "addDev",
        name: "AccessAddDev",
        component: () => import("@/views/access/dev/addDev.vue"),
      },
      {
        path: "editDev",
        name: "AccessEditDev",
        component: () => import("@/views/access/dev/editDev.vue"),
      },

      // 门
      {
        path: "door",
        name: "AccessDoor",
        component: () => import("@/views/access/door/index.vue"),
      },
      {
        path: "addDev",
        name: "AccessAddDoor",
        component: () => import("@/views/access/door/add.vue"),
      },
      {
        path: "editDev",
        name: "AccessEditDoor",
        component: () => import("@/views/access/door/edit.vue"),
      },

      // 时段
      {
        path: "timezone",
        name: "AccessTimezone",
        component: () => import("@/views/access/timezone/index.vue"),
      },
      {
        path: "addTimezone",
        name: "AddTimezone",
        component: () => import("@/views/access/timezone/add.vue"),
      },
      {
        path: "editTimezone",
        name: "EditTimezone",
        component: () => import("@/views/access/timezone/edit.vue"),
      },
      // 区域
      {
        path: "area",
        name: "AccessArea",
        component: () => import("@/views/access/area/index.vue"),
      },
      {
        path: "addAccessArea",
        name: "AddAccessArea",
        component: () => import("@/views/access/area/add.vue"),
      },
      {
        path: "editAccessArea",
        name: "EditAccessArea",
        component: () => import("@/views/access/area/edit.vue"),
      },
      // 进出记录
      {
        path: "inout",
        name: "AccessInout",
        component: () => import("@/views/access/inout/index.vue"),
      },
    ],
  },

  // 考勤模块
  {
    path: "/attend",
    name: "Attend",
    children: [
      // 考勤组
      {
        path: "team",
        name: "Team",
        component: () => import("@/views/attend/team/index.vue"),
      },
      {
        path: "teamAdd",
        name: "TeamAdd",
        component: () => import("@/views/attend/team/addTeam.vue"),
      },
      {
        path: "teamEdit",
        name: "TeamEdit",
        component: () => import("@/views/attend/team/editTeam.vue"),
      },
      {
        path: "teamEmployee",
        name: "TeamEmployee",
        component: () => import("@/views/attend/team/employeeList.vue"),
      },
      {
        path: "teamEmployeeAdd",
        name: "TeamEmployeeAdd",
        component: () => import("@/views/attend/team/addEmployee.vue"),
      },

      // 考勤规则
      {
        path: "rule",
        name: "AttentRule",
        component: () => import("@/views/attend/rule/index.vue"),
      },
      {
        path: "ruleAdd",
        name: "AttentRuleAdd",
        component: () => import("@/views/attend/rule/add.vue"),
      },
      {
        path: "ruleEdit",
        name: "AttentRuleEdit",
        component: () => import("@/views/attend/rule/edit.vue"),
      },
      // 考勤计划
      {
        path: "plan",
        name: "AttentPlan",
        component: () => import("@/views/attend/plan/index.vue"),
      },
      {
        path: "planAdd",
        name: "AttentPlanAdd",
        component: () => import("@/views/attend/plan/add.vue"),
      },
      {
        path: "planEdit",
        name: "AttentPlanEdit",
        component: () => import("@/views/attend/plan/edit.vue"),
      },
      // 考勤点
      {
        path: "point",
        name: "AttendPoint",
        component: () => import("@/views/attend/point/index.vue"),
      },
      {
        path: "addAttendPoint",
        name: "AddAttendPoint",
        component: () => import("@/views/attend/point/add.vue"),
      },
      // 进出记录
      {
        path: "inout",
        name: "AttendInout",
        component: () => import("@/views/attend/inout/index.vue"),
      },
    ],
  },

  // 消费模块
  {
    path: "/pos",
    name: "Pos",
    children: [
      // 设备
      {
        path: "dev",
        name: "PosDev",
        component: () => import("@/views/pos/dev/index.vue"),
      },
      {
        path: "addDev",
        name: "PosAddDev",
        component: () => import("@/views/pos/dev/addDev.vue"),
      },
      {
        path: "editDev",
        name: "PosEditDev",
        component: () => import("@/views/pos/dev/editDev.vue"),
      },

      // 规则
      {
        path: "casbin",
        name: "PosCasbin",
        component: () => import("@/views/pos/casbin/index.vue"),
      },
      {
        path: "addCasbin",
        name: "PosAddCasbin",
        component: () => import("@/views/pos/casbin/addCasbin.vue"),
      },
      {
        path: "editCasbin",
        name: "PosEditCasbin",
        component: () => import("@/views/pos/casbin/editCasbin.vue"),
      },
      {
        path: "employeeList",
        name: "PosEmployeeList",
        component: () => import("@/views/pos/casbin/employeeList.vue"),
      },
      {
        path: "addEmployee",
        name: "PosAddEmployee",
        component: () => import("@/views/pos/casbin/addEmployee.vue"),
      },
      {
        path: "deviceList",
        name: "PosDeviceList",
        component: () => import("@/views/pos/casbin/deviceList.vue"),
      },
      {
        path: "addDevice",
        name: "PosAddDevice",
        component: () => import("@/views/pos/casbin/addDevice.vue"),
      },
      {
        path: "walletCategoryList",
        name: "PosWalletCategoryList",
        component: () => import("@/views/pos/casbin/walletCategoryList.vue"),
      },
      {
        path: "addWalletCategory",
        name: "PosAddCasbinWalletCategory",
        component: () => import("@/views/pos/casbin/addWalletCategory.vue"),
      },

      // 钱包类别
      {
        path: "walletCategory",
        name: "PosWalletCategory",
        component: () => import("@/views/pos/walletCategory/index.vue"),
      },
      {
        path: "addWalletCategory",
        name: "PosAddWalletCategory",
        component: () =>
          import("@/views/pos/walletCategory/addwalletCategory.vue"),
      },
      {
        path: "editWalletCategory",
        name: "PosEditWalletCategory",
        component: () =>
          import("@/views/pos/walletCategory/editwalletCategory.vue"),
      },

      // 钱包
      {
        path: "wallet",
        name: "PosWallet",
        component: () => import("@/views/pos/wallet/index.vue"),
      },
      {
        path: "addWallet",
        name: "PosAddWallet",
        component: () => import("@/views/pos/wallet/addwallet.vue"),
      },
      {
        path: "editWallet",
        name: "PosEditWallet",
        component: () => import("@/views/pos/wallet/editwallet.vue"),
      },

      // 消费记录
      {
        path: "costLog",
        name: "CostLog",
        component: () => import("@/views/pos/costLog/index.vue"),
      },
      // 充值记录
      {
        path: "chargLog",
        name: "ChargLog",
        component: () => import("@/views/pos/chargLog/index.vue"),
      },
    ],
  },

  // 视频监控
  {
    path: "/monitor",
    name: "Monitor",
    children: [
      // 设备
      {
        path: "dev",
        name: "MonitorDev",
        component: () => import("@/views/monitor/dev/index.vue"),
      },
      {
        path: "dev",
        name: "MonitorAddDev",
        component: () => import("@/views/monitor/dev/add.vue"),
      },
      {
        path: "dev",
        name: "MonitorEditDev",
        component: () => import("@/views/monitor/dev/edit.vue"),
      },
      {
        path: "look",
        name: "MonitorDevLook",
        component: () => import("@/views/monitor/dev/look.vue"),
      },
    ],
  },
];

const router = createRouter({
  history: createWebHashHistory(),
  routes,
});

// 路由加载前
// router.beforeEach((to, from, next) => {
//   const token = LocalCache.get("token");
//   if (to.path === "/login" && !token) {
//     next();
//   } else {
//     if (!token) {
//       LocalCache.clear();
//       next(`/login`);
//     } else if (token && to.path === "/login") {
//       next("/index");
//     } else {
//       next();
//     }
//   }
// });

export default router;
